//
//  FPRankTableViewCell.m
//  FilmParadise
//
//  Created by lanou3g on 15/7/15.
//  Copyright (c) 2015年 DLYgroup. All rights reserved.
//

#import "FPRankTableViewCell.h"

@implementation FPRankTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{   CGFloat leftSpace = 10;
     CGFloat upSpace = 10;
     CGFloat rightSpace = 10;
     CGFloat picLabelSpace = 10;
     CGFloat downSpace = 10;
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //序列号
        self.numLabel = [[UILabel alloc]initWithFrame:CGRectMake(kImageW(leftSpace), kImageH(upSpace), kImageW(20), kImageW(20))];
        self.numLabel.textAlignment = NSTextAlignmentCenter;
        self.numLabel.layer.cornerRadius = self.numLabel.bounds.size.width/2;
        self.numLabel.layer.masksToBounds = YES;
        [self.contentView addSubview:_numLabel];
        //图片
        self.picImageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.numLabel.width + self.numLabel.x + kImageW(leftSpace), kImageW(upSpace), kImageW(80), kImageH(120))];
        self.picImageView.image = [UIImage imageNamed:@"3.jpg"];
        [self.contentView addSubview:_picImageView];
        
        self.filmNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.picImageView.width + self.picImageView.x + kImageW(rightSpace), kImageH(upSpace), kImageW(80), kImageW(20))];
      //  self.filmNameLabel.backgroundColor = [UIColor redColor];
        self.filmNameLabel.font = [UIFont systemFontOfSize:13];
        self.filmNameLabel.text = @"透明人生";
        [self.contentView addSubview:_filmNameLabel];
        //评分
        self.scoreLabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenWidth - kImageW(60), kImageH(upSpace), kImageW(30), kImageW(20))];
        self.scoreLabel.font = [UIFont systemFontOfSize:11];
        self.scoreLabel.backgroundColor = [UIColor greenColor];
        self.scoreLabel.textAlignment = NSTextAlignmentCenter;
        self.scoreLabel.text = @"8.7";
        [self.contentView addSubview:_scoreLabel];
        
        //电影译文
        self.EnglishNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.filmNameLabel.x,self.filmNameLabel.y + self.filmNameLabel.height + kImageH(5), kScreenWidth, kImageW(20))];
          self.EnglishNameLabel.font = [UIFont systemFontOfSize:11];
        self.EnglishNameLabel.text = @"Transparent";
        [self.contentView addSubview:_EnglishNameLabel];

        //导演
        self.directorLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.filmNameLabel.x,self.EnglishNameLabel.y + self.EnglishNameLabel.height + kImageH(5), kImageW(30), kImageW(20))];
        self.directorLabel.text = @"导演:";
          self.directorLabel.font = [UIFont systemFontOfSize:11];
        [self.contentView addSubview:_directorLabel];
        //导演名
        self.directorNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.directorLabel.x + self.directorLabel.width + kImageW(10),self.EnglishNameLabel.y + self.EnglishNameLabel.height + kImageH(5), kScreenWidth, kImageW(20))];
        self.directorNameLabel.text = @"吉尔.索罗威";
        self.directorNameLabel.font = [UIFont systemFontOfSize:11];
        [self.contentView addSubview:_directorNameLabel];
        
        //主演
        self.roleLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.directorLabel.x,self.directorLabel.y + self.directorLabel.height + kImageH(5), kImageW(30), kImageW(20))];
        self.roleLabel.text = @"主演:";
        self.roleLabel.font = [UIFont systemFontOfSize:11];
        [self.contentView addSubview:_roleLabel];
        //主演名
        self.roleNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.directorLabel.x + self.directorLabel.width + kImageW(10),self.directorNameLabel.y + self.directorNameLabel.height + kImageH(5), kScreenWidth, kImageW(20))];
        self.roleNameLabel.text = @"吉尔.索罗威";
        self.roleNameLabel.font = [UIFont systemFontOfSize:11];
        [self.contentView addSubview:_roleNameLabel];

        //上映
        self.showTimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.roleLabel.x,self.roleLabel.y + self.roleLabel.height + kImageH(5), kImageW(50), kImageW(20))];
        self.showTimeLabel.text = @"上映时间:";
        self.showTimeLabel.font = [UIFont systemFontOfSize:11];
        [self.contentView addSubview:_showTimeLabel];
        //时间
        self.TimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.showTimeLabel.x + self.showTimeLabel.width + kImageW(10),self.roleLabel.y + self.roleLabel.height + kImageH(5), kScreenWidth/4, kImageW(20))];
        self.TimeLabel.text = @"2014年7月15日";
        self.TimeLabel.font = [UIFont systemFontOfSize:11];
        [self.contentView addSubview:_TimeLabel];
        
        //添加文字label
        self.introLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.picImageView.x ,self.picImageView.y + self.picImageView.height + kImageH(picLabelSpace), kScreenWidth - 2 *self.picImageView.x, kImageH(50))];
        self.introLabel.backgroundColor = [UIColor lightGrayColor];
        self.introLabel.alpha = 0.5;
        self.introLabel.userInteractionEnabled = YES;
        self.introLabel.font = [UIFont systemFontOfSize:11];
        self.introLabel.numberOfLines = 0;
        [self.contentView addSubview:_introLabel];
        
        //国家
        self.countryLabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenWidth - kImageW(60),self.roleLabel.y + self.roleLabel.height + kImageH(5), kImageW(30), kImageW(20))];
        self.countryLabel.text = @"美国";
        self.countryLabel.font = [UIFont systemFontOfSize:11];
        [self.contentView addSubview:_countryLabel];
        
    }
    return self;
}

//给cell赋值
- (void)cellforModel:(FPRankModel *)rankModel
{
    if (rankModel)
    {
        self.introLabel.text = rankModel.remark;
        [self.picImageView sd_setImageWithURL:[NSURL URLWithString:rankModel.posterUrl] placeholderImage:nil completed:nil];;
        self.scoreLabel.text = [NSString stringWithFormat:@"%.1f",rankModel.rating] ;
        self.filmNameLabel.text = rankModel.name;
        self.EnglishNameLabel.text = rankModel.nameEn;
        self.directorNameLabel.text = rankModel.director;
        self.roleNameLabel.text = rankModel.actor;
        self.TimeLabel.text = rankModel.releaseDate;
        self.countryLabel.text = rankModel.releaseLocation;
    }
   
    
}
//计算label的高
- (void)adjustSubviewsWithContent:(FPRankModel *)rankModel
{
    self.introLabel.text = rankModel.remark;
    CGRect bounds = [rankModel.remark boundingRectWithSize:CGSizeMake(kScreenWidth - 2 *self.picImageView.x , 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:11] forKey:NSFontAttributeName] context:nil];
    self.introLabel.font = [UIFont systemFontOfSize:11];
    NSLog(@"%f",bounds.size.height);
    self.introLabel.height = bounds.size.height;
}

//计算cell的高
+ (CGFloat)heightForCell:(FPRankModel *)rankModel
{
    CGRect bounds = [rankModel.remark boundingRectWithSize:CGSizeMake(kScreenWidth - 2 * kImageW(60) , 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:11] forKey:NSFontAttributeName] context:nil];
    return bounds.size.height + 2 * kImageH(10) + kImageH(120);
}
@end
